package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysArea;
import com.ruoyi.system.service.ISysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 区域信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/area")
public class SysAreaController extends BaseController {

    @Autowired
    private ISysAreaService areaService;

    /**
     * 获取区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public AjaxResult list() {
        List<SysArea> areaList = areaService.selectAreaList();
        return success(areaList);
    }

    /**
     * 添加区域
     */
    @PreAuthorize("@ss.hasPermi('system:area:create')")
    @PostMapping("/create")
    public AjaxResult create(@Validated @RequestBody SysArea area){
        return success(areaService.createArea(area));
    }
    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('system:area:delete')")
    @PostMapping("/delete")
    public Object delete(@Validated @RequestBody SysArea area){
        Long id = area.getId();
        return success(areaService.deleteArea(id));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('system:area:update')")
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody SysArea area){
        areaService.updateArea(area);
        return success();
    }
}
